export default function (global, console) {
  global.showHeaders = function () {
    const request = new XMLHttpRequest()
    request.open('HEAD', window.location)
    request.onload = request.onerror = function () {
      const headers = request.getAllResponseHeaders()
      const headersTable = headers
        .split('\n')
        .map((header) => ({ Key: header.split(': ')[0], Value: header.split(': ')[1] }))
        .filter((header) => header.Value !== undefined)

      console.group('Request Headers')
      console.log(headers)
      console.table(headersTable)
      console.groupEnd('Request Headers')
    }
    request.send()
  }
}
